#include "dialogtemplate.h"
#include "ui_dialogtemplate.h"

#include <QDesktopServices>
#include <QDebug>
DialogTemplate::DialogTemplate(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::DialogTemplate)
{
    ui->setupUi(this);
    setWindowFlags(Qt::FramelessWindowHint |
                   Qt::Tool | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint);
    ui->lb_website->setText(tr("<a href = 'http://javacgo.com'>Website: www.javacgo.com</a>"));
}
DialogTemplate::DialogTemplate(QWidget *parent,const QString &title) :
    QDialog(parent),
    ui(new Ui::DialogTemplate)
{
    ui->setupUi(this);
    setWindowFlags(Qt::FramelessWindowHint |
                   Qt::Tool | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint);
    ui->lb_title->setText(title);
}
DialogTemplate::~DialogTemplate()
{
    delete ui;
}

void DialogTemplate::mousePressEvent(QMouseEvent *e)
{
    last = e->globalPos();
    c_press = e->pos();

}
void DialogTemplate::mouseMoveEvent(QMouseEvent *e)
{

    if(c_press.y()>ui->panel_aup->height()){
        return ;
    }
    int dx = e->globalX() - last.x();
    int dy = e->globalY() - last.y();
    last = e->globalPos();
    move(x()+dx, y()+dy);
}
void DialogTemplate::mouseReleaseEvent(QMouseEvent *e)
{
    if(c_press.y()>ui->panel_aup->height()){
        return ;
    }
    int dx = e->globalX() - last.x();
    int dy = e->globalY() - last.y();
    move(x()+dx, y()+dy);
}

void DialogTemplate::on_btn_close_clicked()
{
    this->hide();
}

void DialogTemplate::on_lb_website_linkActivated(const QString &link)
{
    qDebug()<<"link";
    QDesktopServices::openUrl(QUrl(link));
}
